#set(entityClassName = table.buildEntityClassName())
#set(defTable = tableDefConfig.buildFieldName(table.getName()))
#set(tableDefClassName = table.buildTableDefClassName())
package #(packageConfig.mapperPackage);

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import #(queryPk).#(queryEntity);
#if(mapperConfig.isMapperAnnotation())
import org.apache.ibatis.annotations.Mapper;
#end
import #(mapperConfig.buildSuperClassImport());
import com.mybatisflex.core.query.QueryWrapper;
import #(packageConfig.entityPackage).#(table.buildEntityClassName());
import #(packageConfig.tableDefPackage).#(tableDefClassName);
/**
 * #(table.getComment()) 映射层。
 *
 * @author #(javadocConfig.getAuthor())
 * @since #(javadocConfig.getSince())
 */
#if(mapperConfig.isMapperAnnotation())
@Mapper
#end
public interface #(table.buildMapperClassName()) extends #(mapperConfig.buildSuperClassName())<#(table.buildEntityClassName())> {


    static QueryWrapper createWrapper(#(queryEntity) query){
       QueryWrapper wrapper = QueryWrapper.create();
#for(column: table.getSortedColumns())
   #if(column.propertySimpleType == 'String')
       wrapper.and(#(tableDefClassName).#(tableDefConfig.buildFieldName(table.getName())).#(tableDefConfig.buildFieldName(column.property)).like(query.#(column.getterMethod())()).when(StrUtil.isNotBlank(query.#(column.getterMethod())())));
   #else if(column.propertySimpleType == 'Boolean')
       wrapper.and(#(tableDefClassName).#(tableDefConfig.buildFieldName(table.getName())).#(tableDefConfig.buildFieldName(column.property)).eq(query.#(column.getterMethod())()).when(Boolean.TRUE.equals(query.#(column.getterMethod())())));
   #else
       wrapper.and(#(tableDefClassName).#(tableDefConfig.buildFieldName(table.getName())).#(tableDefConfig.buildFieldName(column.property)).eq(query.#(column.getterMethod())()).when(ObjUtil.isNotNull(query.#(column.getterMethod())())));
   #end
#end
       return wrapper;
   }
}
